#include "frmtecherlst.h"
#include "ui_frmtecherlst.h"

FrmTecherlst::FrmTecherlst(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FrmTecherlst)
{
    ui->setupUi(this);
    this->initForm();
}

FrmTecherlst::~FrmTecherlst()
{
    delete ui;
}

void FrmTecherlst::initForm()
{
    ui->tableWidget->setColumnCount(4);
    ui->tableWidget->setRowCount(3);

    ui->tableWidget->setHorizontalHeaderLabels(QStringList()<<"姓名"<<"性别"<<"科目"<<"入职时间");

    ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::Stretch);

    QList<TecherModel> lst=QTECHSchedDataHelper::getTeachers();
    QList<SubjectModel> subjlst=QTECHSchedDataHelper::getSubjects();
    foreach (TecherModel m, lst) {
        QString strSex=m.getSex()==0?"男":"女";
        QString strSubj="";
        foreach (SubjectModel subj, subjlst) {
            if(m.getSubjcode()==subj.getCode())
            {
                strSubj=subj.getName();
            }
        }
        QString strOntime=m.getOntime().toString("yyyy-MM-dd");
        appendRow(QStringList()<<m.getName()<<strSex<<strSubj<<strOntime);

    }
}

void FrmTecherlst::appendRow(const QStringList lst)
{
    static qint16 row=0;
    qint16 col=0;
    foreach (QString str, lst) {
        QTableWidgetItem *item=new QTableWidgetItem(str);
        item->setTextAlignment(Qt::AlignLeft);

        ui->tableWidget->setItem(row,col++,item);
    }

    row++;
}
